package com.rzx.mybackend.mapper;

import com.rzx.mybackend.entity.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * RoleMapper
 *
 * @author renzhexian
 * @date 2025/7/15
 */

@Mapper
public interface RoleMapper {
    /*
    根据用户ID查询角色信息
     */
    @Select("SELECT role_name FROM sys_role WHERE role_id = (SELECT role_id FROM sys_user_role WHERE user_id = #{userId})")
    List<Role> selectByUserId(Long userId);

    /*
    根据用户名查询用户角色
     */
    @Select("SELECT role_name FROM sys_role WHERE role_id = (SELECT role_id FROM sys_user_role WHERE user_id = (SELECT user_id FROM sys_user WHERE user_name = #{userName}))")
    String selectByUserUserName(String userName);
}
